// JavaScript Document
define(function (require, exports, module) {
	var List=function(selector,options){
		this.element=$(selector).get(0);
		this.options=options;
	}
	List.prototype.snEnable=false;
	List.prototype.getIdArray=function(){
		var idArray=Array();
		for(var i=0;i<this.total;i++){
			idArray.push(this.listItems[i].getId());
		}
		return idArray
	}
	//更新
	List.prototype.update=function(){
		this.listItems=new Array();
		this.children=this.element.children;
		this.total=this.children.length;
		for(var i=0;i<this.total;i++){
			listItem=new this.ListItem(this.children[i],i,this.options);
			if(this.snEnable){
				listItem.setSn(i);
			}
			this.listItems.push(listItem);
		}
	}
	//获得列表元素
	List.prototype.getItem=function(index){
		var item=this.listItems[index]
		return item;
	}
	List.prototype.getItemById=function(id){
		for(var i=0;i<this.total;i++){
			var item=this.listItems[i]
			if(item.getId()==id){
				return item;
			}
		}
		return null;
	}
	//添加列表元素
	List.prototype.append=function(item){
		//var element=$(item.element).clone();
		var element=item.element
		$(this.element).append(element);
		this.update();
	}
	//移除
	List.prototype.remove=function(num){
		var item=this.getItem(num);
		if(item!=null){
			var element=item.element;
			$(element).remove()
			delete item;
			this.update();
		}
	}
	List.prototype.removeById=function(id){
		var item=this.getItemById(id);
		if(item!=null){
			var element=item.element;
			$(element).remove()
			delete item;
			this.update();
		}
	}
	//选择
	List.prototype.select=function(num){
		var item=this.getItem(num)
		if(item!=null){
			item.select();
		}
	}
	List.prototype.selectById=function(id){
		var item=this.getItemById(id)
		if(item!=null){
			item.select();
		}
	}
	//取消选择
	List.prototype.deselect=function(num){
		var item=this.getItem(num)
		if(item!=null){
			item.deselect();
		}
	}
	List.prototype.deselectById=function(id){
		var item=this.getItemById(id)
		if(item!=null){
			item.deselect();
		}
	}
	module.exports = List;
});